# test.py (关键部分修改)
import json
import sys
from work.vul_mock_server import  VulnMockServer
sys.path.append('E:/Agent')  # 根据实际情况调整路径
from work.threatDiscovery import ThreatDiscovery
import threading
# 模拟 RabbitMQ 类
class MockRabbitMQ:
    def produce_system_vul_info(self, data):
        print(f"Producing app vulnerability info: {data}")
        # 打印解析后的JSON数据，便于查看
        try:
            print(f"漏洞数据解析: {json.loads(data)}")
        except:
            pass

    def produce_vul_info(self, data):
        print(f"Producing vulnerability info: {data}")
        # 打印解析后的JSON数据，便于查看
        try:
            print(f"漏洞数据解析: {json.loads(data)}")
        except:
            pass

# 模拟输入数据（关键修改部分）
data = {
    "hotfix": 0,
    "vulnerability": 0,
    "weakPassword": 0,
    "application": 0,  # 开启应用漏洞检测
    "system": 1,
    "macAddress": "00:11:22:33:44:55",
    "vulnerabilities": [
        {
            "id": 1,
            "vulPath": "/test/path1",  # 与模拟服务路径一致
            "vulRequestType": "GET",        # 请求方法
            "payload": "?test=1",        # GET请求参数
            "vulFlag": "vulnerable"   # 漏洞标志（需包含在响应中）
        },
        {
            "id": 2,
            "vulPath": "/test/path2",  # 与模拟服务路径一致
            "vulRequestType": "POST",       # 请求方法
            "payload": "data=test",      # POST请求数据
            "vulFlag": "vulnerable"   # 漏洞标志（需包含在响应中）
        }
    ]
}

server = VulnMockServer()
server.start()

# 创建 ThreatDiscovery 实例并执行检测
rabbitmq = MockRabbitMQ()
threat_discovery = ThreatDiscovery(rabbitmq, data)
threat_discovery._ThreatDiscovery__system_vulnerability_discovery()